package org.yourscrum.testutil;

import static org.junit.Assert.fail;
import org.yourscrum.domain.AbstractEntity;

import java.lang.reflect.Field;

/**
 * @author Jettro Coenradie
 */
public class SetIdFieldUtil {
    public static void execute(AbstractEntity entity, Long idValue) {
        try {
            Field idField = AbstractEntity.class.getDeclaredField("id");
            idField.setAccessible(true);
            idField.set(entity, idValue);
        } catch (NoSuchFieldException e) {
            fail("Field id could not be obtained using reflection");
        } catch (IllegalAccessException e) {
            fail("Field id could not be set using reflection");
        }

    }
}
